package net.towee.model.repo.impl;

import net.towee.model.account.AccountIdentity;
import net.towee.model.discussion.DiscussionSubject;
import net.towee.model.repo.AttachmentIdentity;
import net.towee.model.repo.AttachmentPictureIdentity;
import net.towee.model.repo.AttachmentTorrentIdentity;
import net.towee.model.repo.AttachmentType;
import net.towee.model.repo.DocumentIdentity;
import net.towee.server.persistence.impl.MongoDbStore;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

/**
 * Implementation of attachment identity
 * @author c58
 */
@Entity(MongoDbStore.ATTACH_IDENTITY_COLLECTION)
public class AttachmentIdentityImpl implements AttachmentIdentity, AttachmentPictureIdentity,
	AttachmentTorrentIdentity {
	// Picture
	private int width;
	private int height;
	
	// Torrent
	private long contentSize;
	
	// General
	@Id protected String id;
	protected String name;
	protected long size;
	protected long downloads;
	protected AttachmentType type;
	
	public AttachmentIdentityImpl() {}
	public AttachmentIdentityImpl(String id, String name, long size, AttachmentType type) {
		this.id = id;
		this.name = name;
		this.size = size;
		this.type = type;
		this.downloads = 0;
	}
	
	@Override
	public String getId() {
		return id;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public long getDownloads() {
		return downloads;
	}

	@Override
	public long getSize() {
		return size;
	}

	@Override
	public AttachmentType getType() {
		return type;
	}
	
	@Override
	public boolean equals(Object o){
		if(o == this)
			return true;
		if(o instanceof AttachmentIdentity && ((AttachmentIdentity)o).getId().equals(this.getId()))
			return true;
		
		return false;
	}
	
	@Override
	public String toString() {
		return id;
	}
	
	/*
	 * PICTURE
	 */
	@Override
	public int getWidth() {
		return width;
	}
	@Override
	public int getHeight() {
		return height;
	}
	@Override
	public void setPictureSize(int width, int height) {
		this.width = width;
		this.height = height;
	}
	
	/*
	 * TORRENT
	 */
	@Override
	public long getContentSize() {
		return contentSize;
	}
	@Override
	public void setContentSize(long size) {
		this.contentSize = size;
	}
	
	/*
	 * HELPERS
	 */
	@Override
	public AttachmentPictureIdentity toPicture() {
		return this;
	}
	@Override
	public AttachmentTorrentIdentity toTorrent() {
		return this;
	}
}
